import React, { useReducer } from 'react';
import { commonConst } from '../commons/consts/common-const';
import { individuationConst } from '../commons/consts/individuation-const';
import CookieUtils from '../commons/utils/cookie-util';
import AppLayoutContext from '../contexts/app-layout-context';
import { appLayoutReducer } from '../reducers/app-layout-reducer';
import AdminLayout from './AdminLayout';
import DeskLayout from './DeskLayout';

const AppLayout:React.FC<{route:any}> = ({ route }:any) => {
    const [appLayoutState, dispatchAppLayoutState] = useReducer(appLayoutReducer, { layout: CookieUtils.get(commonConst.sessionLayout) as string });

    const getLayout = () => {
        switch (appLayoutState.layout) {
            case individuationConst.layout.deskLayout:
                return (<DeskLayout route={route} />);
            default:
                return (<AdminLayout route={route} />)
        }
    }
    return (
        <AppLayoutContext.Provider value={dispatchAppLayoutState}>
            {
                getLayout()
            }
        </AppLayoutContext.Provider>
    )
};

export default AppLayout;
